/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exec;

import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author fromenje
 */
public class GUI extends javax.swing.JFrame {

    Client client;

    /**
     * Creates new form GUI
     */
    public GUI() {
        initComponents();
        editorPane1.setEditable(false);
        menuDisconnect.setVisible(false);
        openedTabs.add(new Tabs("All", editorPane1));
        //progressBar.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        container = new javax.swing.JSplitPane();
        containerList = new javax.swing.JScrollPane();
        list = new javax.swing.JList();
        containerTabs = new javax.swing.JTabbedPane();
        tab1 = new javax.swing.JScrollPane();
        editorPane1 = new javax.swing.JEditorPane();
        textField = new javax.swing.JTextField();
        buttonSend = new javax.swing.JButton();
        buttonErase = new javax.swing.JButton();
        status = new javax.swing.JFormattedTextField();
        buttonFichier = new javax.swing.JButton();
        buttonFermerOnglet = new javax.swing.JButton();
        progressBar = new javax.swing.JProgressBar();
        menuBar = new javax.swing.JMenuBar();
        connectItem = new javax.swing.JMenu();
        menuConnect = new javax.swing.JMenuItem();
        menuDisconnect = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        container.setDividerLocation(570);
        container.setDividerSize(10);
        container.setAutoscrolls(true);
        container.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        container.setRequestFocusEnabled(false);

        list.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i];}
        });
        MouseListener mouseListener = new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    int index = list.locationToIndex(e.getPoint());
                    String concernedUser = (String) list.getModel().getElementAt(index);

                    boolean found = false;
                    for (int i=0; i<openedTabs.size(); i++)
                    if (openedTabs.elementAt(i).getNomTab().equals(concernedUser))
                    found = true;

                    if (!found) {
                        createTab(concernedUser);
                    }
                    selectTab(concernedUser);
                }
            }
        };
        list.addMouseListener(mouseListener);
        list.setEnabled(false);
        containerList.setViewportView(list);

        container.setRightComponent(containerList);

        containerTabs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabClicked(evt);
            }
        });

        editorPane1.setDragEnabled(true);
        editorPane1.setContentType( "text/html" );
        tab1.setViewportView(editorPane1);

        containerTabs.addTab("All", tab1);

        container.setLeftComponent(containerTabs);

        textField.setText("Entrez votre texte ici...");
        textField.setEnabled(false);
        //textField.setDropMode(DropMode.INSERT);
        textField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                textFieldMouseClicked(evt);
            }
        });
        textField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                textFieldFocusLost(evt);
            }
        });
        textField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldKeyTyped(evt);
            }
        });

        buttonSend.setText("Envoyer");
        buttonSend.setEnabled(false);
        buttonSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSendActionPerformed(evt);
            }
        });
        buttonSend.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                buttonSendKeyTyped(evt);
            }
        });

        buttonErase.setText("Effacer");
        buttonErase.setEnabled(false);
        buttonErase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEraseActionPerformed(evt);
            }
        });

        status.setFocusable(false);

        buttonFichier.setText("Fichier...");
        buttonFichier.setEnabled(false);
        buttonFichier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonFichierActionPerformed(evt);
            }
        });

        buttonFermerOnglet.setText("Fermer Onglet");
        buttonFermerOnglet.setEnabled(false);
        buttonFermerOnglet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonFermerOngletActionPerformed(evt);
            }
        });

        connectItem.setMnemonic('f');
        connectItem.setText("File");

        menuConnect.setText("Connect");
        menuConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuConnectActionPerformed(evt);
            }
        });
        connectItem.add(menuConnect);

        menuDisconnect.setMnemonic('s');
        menuDisconnect.setText("Disconnect");
        menuDisconnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuDisconnectActionPerformed(evt);
            }
        });
        connectItem.add(menuDisconnect);

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        connectItem.add(exitMenuItem);

        menuBar.add(connectItem);

        helpMenu.setMnemonic('h');
        helpMenu.setText("Help");

        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText("About");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(container, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 785, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(status)
                    .addComponent(textField, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonSend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonFichier, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(buttonErase, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(buttonFermerOnglet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(container, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(buttonFermerOnglet, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonErase, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(textField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(buttonSend, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonFichier)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private Tabs findTab(String concernedUser) {
        for (int i = 0; i < openedTabs.size(); i++) {
            if (openedTabs.elementAt(i).getNomTab().equals(concernedUser)) {
                return openedTabs.elementAt(i);
            }
        }
        return null;
    }

    private int findTabIndex(String concernedUser) {
        for (int i = 0; i < openedTabs.size(); i++) {
            if (openedTabs.elementAt(i).getNomTab().equals(concernedUser)) {
                return i;
            }
        }
        return -1;
    }

    public void selectTab(String concernedUser) {
        for (int j = 0; j < openedTabs.size(); j++) {
            if (openedTabs.elementAt(j).getNomTab().equals(concernedUser)) {
                containerTabs.setSelectedIndex(j);
            }
        }
    }

    public Tabs selectTabR(String concernedUser) {
        for (int j = 0; j < openedTabs.size(); j++) {
            if (openedTabs.elementAt(j).getNomTab().equals(concernedUser)) {
                containerTabs.setSelectedIndex(j);
                return openedTabs.elementAt(j);
            }
        }
        return null;
    }

    public void createTab(String concernedUser) {
        JEditorPane jEditorPane = new javax.swing.JEditorPane();
        JScrollPane tab = new javax.swing.JScrollPane();
        tab.setViewportView(jEditorPane);

        Tabs tabHolder = new Tabs(concernedUser, jEditorPane);
        containerTabs.addTab(concernedUser, tab);
        openedTabs.add(tabHolder);
        tabHolder.getTab().setEditable(false);
        tabHolder.getTab().setContentType("text/html");
    }

    public void connect(String server, String port, String nickname) {
        client = new Client(server, port, nickname, this);
        client.connect();
    }

    public void updateClientList(String listString) {
        // je crains qu'on ai des problèmes lorsqu'un nick contient des caractères d'un autre nick. Genre bob et megabob.
        // Trop galère de recopier dans un tableau, vois ce que t'en penses. Une solution est d'encadrer tous les pseudos par des espaces (devant et derrière),
        // et de virer le premier espace dans la liste. Mais c'est pas beau.
//        System.err.println("debug list : " + listString);
        listString = listString.replace("/" + client.getNickname() + " ", "");
        listString = listString.replaceAll("/", "");
        clientsList = listString.split(" ");

        if (!listString.contains(getCurrentTab()) && !getCurrentTab().equals("All")) {
            tabAppend(selectTabR(getCurrentTab()), "<b><i>" + getCurrentTab() + " is now disconnected.</i></b>");
        }
//        for(int i=0; i<clientsList.length;i++) {
//            System.err.println("Contenu de clientsList à i="+i+" : " + clientsList[i]);
//        }
//        String[] temp = new String[clientsList.length];
//        
//        for(int i = 0; i<clientsList.length; i++) {
//            if (!(clientsList[i].equals(client.getNickname()))) {
//                temp[i] = clientsList[i];
//            }
//        }
        list.setModel(new javax.swing.AbstractListModel() {

            String[] strings = clientsList;

            @Override
            public int getSize() {
                return strings.length;
            }

            @Override
            public Object getElementAt(int i) {
                return strings[i];
            }
        });
    }

    public void updateStatus(String message) {
        status.setText(message);
    }

    // marche pas, t'as une meilleure idée ? Le thread.sleep dans une boucle, c'est moyen, mais j'ai pas trop d'autre solution...
    public void flashLightTab(String concernedUser) {
        int index = findTabIndex(concernedUser);
        Color color = containerTabs.getComponentAt(index).getBackground();
        for (int i = 0; i < 20; i++) {
            containerTabs.getComponentAt(index).setBackground(Color.red);
            try {
                Thread.sleep(300);
            } catch (InterruptedException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
            containerTabs.getComponentAt(index).setBackground(color);
        }
        containerTabs.getComponentAt(index).setBackground(color);
    }

    public void updateTextArea(String nick, String message, boolean all) {
        Date time = new Date();
        Tabs tab;
        SimpleDateFormat ft = new SimpleDateFormat("'['HH:mm']'");
        String line = "<i>" + ft.format(time) + "</i>" + " " + nick + " : " + message;

        // to check : comment se comporte le bordel si t'écris une phrase longue... 
        if (nick.equals(client.getNickname())) {
            tab = openedTabs.elementAt(containerTabs.getSelectedIndex());
            line = "<font color=\"green\">".concat(line.concat("</font>"));
        } else if (all) {
            tab = findTab("All");
        } else {
            tab = findTab(nick);
            if (tab == null) {
                // cas où on reçoit un PM d'un client avec lequel on n'a pas démarré de conv' privée
                createTab(nick);
                tab = selectTabR(nick);
            }
        }
        tabAppend(tab, line);
    }

    private void tabAppend(Tabs tab, String message) {
        // Balance la sauce coco.
        // Seule façon de faire. Passé du temps dessus.
        String oldText = tab.getTab().getText().replace("<html>", "").replace("</html>", "");
        tab.getTab().setText(oldText.substring(0, oldText.indexOf("</body>")) + message + "<br />" + oldText.substring(oldText.indexOf("</body>")));
        tab.getTab().setAlignmentY(tab.getTab().getAlignmentY() + 5);
        
        // force l'affichage en bas de page.
        if ((tab.getTab().getDocument()).getLength() > 1) {
            tab.getTab().setCaretPosition((tab.getTab().getDocument()).getLength() - 1);
        }
    }

    private void clearAndSend() {
        //Boom. J'te choppe le nom du destinataire avec le nom de l'onglet.
        //J : Si je puis me permettre, c'est pas sendAndClear, plutôt ? :p
        client.sendMessage(getCurrentTab(), textField.getText());
        textField.setText("");
    }

    // réutilisation ouéch.
    private String getCurrentTab() {
        return openedTabs.elementAt(containerTabs.getSelectedIndex()).getNomTab();
    }

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        if (client.isConnected()) {
            client.disconnect();
        }
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        new About(this).setVisible(true);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void buttonEraseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEraseActionPerformed
        textField.setText("");
    }//GEN-LAST:event_buttonEraseActionPerformed

    private void textFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_textFieldMouseClicked
        if (textField.isEditable() && textField.getText().equals("Entrez votre texte ici...")) {
            textField.setText("");
        }
    }//GEN-LAST:event_textFieldMouseClicked

    private void menuConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuConnectActionPerformed
        connectionPopup = new ConnectionPopup(this);
        connectionPopup.setVisible(true);
    }//GEN-LAST:event_menuConnectActionPerformed

    private void menuDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDisconnectActionPerformed
        client.disconnect();
        showDisconnectMenu(false);
    }//GEN-LAST:event_menuDisconnectActionPerformed

    private void buttonSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSendActionPerformed
        if (textField.getText() != "") {
            clearAndSend();
        }
    }//GEN-LAST:event_buttonSendActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if (client != null && client.isConnected()) {
            client.disconnect();
        }
    }//GEN-LAST:event_formWindowClosing

    private void textFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldKeyTyped
        if (evt.getKeyChar() == KeyEvent.VK_ENTER && textField.getText() != "") {
            clearAndSend();
        } else {
            client.heyImWriting(getCurrentTab());
        }
    }//GEN-LAST:event_textFieldKeyTyped

    private void buttonSendKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_buttonSendKeyTyped
        if (evt.getKeyChar() == KeyEvent.VK_ENTER && textField.getText() != "") {
            clearAndSend();
        }
    }//GEN-LAST:event_buttonSendKeyTyped

    private void tabClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabClicked
        if (!status.getText().equals("Connecté.")) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
            updateStatus("Connecté.");
        }
        
    }//GEN-LAST:event_tabClicked

    private void textFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_textFieldFocusLost
        client.heyImNotWritingAnymore(getCurrentTab());
    }//GEN-LAST:event_textFieldFocusLost

    private void buttonFichierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFichierActionPerformed
        JFileChooser jFileChooser = new JFileChooser();

        int returnValue = jFileChooser.showOpenDialog(this);
        System.err.println("ReturnValue = " + returnValue);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            System.out.println("File selected : " + jFileChooser.getSelectedFile().getName());
            updateStatus("File selected : " + jFileChooser.getSelectedFile().getName());
            try {
                client.sendFile(getCurrentTab(), jFileChooser.getSelectedFile());
            } catch (InterruptedException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);

            } catch (FileNotFoundException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_buttonFichierActionPerformed

    private void buttonFermerOngletActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFermerOngletActionPerformed
        if(openedTabs.elementAt(containerTabs.getSelectedIndex()).getNomTab().equals("All")) {
            alert("Vous ne pouvez pas fermer cet onglet");
        }
        else {
            openedTabs.remove(containerTabs.getSelectedIndex());
            containerTabs.remove(containerTabs.getSelectedComponent());
            selectTab("All");
        }
    }//GEN-LAST:event_buttonFermerOngletActionPerformed

    public void showAll(boolean cond) {
        containerTabs.setEnabled(cond);
        textField.setEnabled(cond);
        buttonSend.setEnabled(cond);
        buttonErase.setEnabled(cond);
        list.setEnabled(cond);
        buttonFichier.setEnabled(cond);
        buttonFermerOnglet.setEnabled(cond);
    }

    public void showConnectMenu(boolean bool) {
        menuConnect.setVisible(bool);
        menuDisconnect.setVisible(!bool);
        connectionPopup.setVisible(bool);
    }

    public void showDisconnectMenu(boolean bool) {
        menuDisconnect.setVisible(bool);
        menuConnect.setVisible(!bool);
    }
    
    public JProgressBar getProgresBar() {
        return progressBar;
    }
    
    public void alert(String message) {
        JOptionPane.showMessageDialog(null, message, "Houston...", JOptionPane.WARNING_MESSAGE);
    }

    public void error(String message) {
        JOptionPane.showMessageDialog(null, message, "Houston...", JOptionPane.ERROR_MESSAGE);
    }

    public void dumpTextArea() {
        editorPane1.setText(null);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JButton buttonErase;
    private javax.swing.JButton buttonFermerOnglet;
    private javax.swing.JButton buttonFichier;
    private javax.swing.JButton buttonSend;
    private javax.swing.JMenu connectItem;
    private javax.swing.JSplitPane container;
    private javax.swing.JScrollPane containerList;
    private javax.swing.JTabbedPane containerTabs;
    private javax.swing.JEditorPane editorPane1;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JList list;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem menuConnect;
    private javax.swing.JMenuItem menuDisconnect;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JFormattedTextField status;
    private javax.swing.JScrollPane tab1;
    private javax.swing.JTextField textField;
    // End of variables declaration//GEN-END:variables
    private ConnectionPopup connectionPopup;
    private Vector<Tabs> openedTabs = new Vector<Tabs>();
    private String[] clientsList;
}
